<template>
  <div class="header-container">
    <div class="header">
      <div class="logo">
        <img src="@/static/images/login/logo.png" alt="" />
        <div class="search">
          <div>
            <span @click="toLogin">登录</span><span @click="toLogin">注册</span>
          </div>
          <el-input placeholder="热门搜索：干花花瓶" :suffix-icon="Search" />
        </div>
      </div>
      <div class="nav">
        <ul>
          <li
            @click="pageJump('/index')"
            :style="{ color: isIndex ? 'red' : '' }"
          >
            首页
          </li>
          <li>所有商品</li>
          <li
            @click="pageJump('/decorate')"
            :style="{ color: isDecorate ? 'red' : '' }"
          >
            装饰摆件
          </li>
          <li>布艺软饰</li>
          <li
            @click="pageJump('/wall-hanging')"
            :style="{ color: isWallHanging ? 'red' : '' }"
          >
            墙式壁挂
          </li>
          <li>蜡艺香薰</li>
          <li>创意家居</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { reactive, defineComponent, toRefs, onMounted } from 'vue';
import { Search } from '@element-plus/icons-vue';
import { useRouter, useRoute } from 'vue-router';

export default defineComponent({
  setup() {
    const router = useRouter();
    const route = useRoute();
    const state = reactive({
      isIndex: false,
      isDecorate: false,
      isWallHanging: false,
    });
    const getRoutePath = () => {
      const path = route.path;
      if (path.includes('index')) {
        state.isIndex = true;
      } else if (path.includes('decorate')) {
        state.isDecorate = true;
      } else if (path.includes('wall-hanging')) {
        state.isWallHanging = true;
      }
    };

    onMounted(() => {
      getRoutePath();
    });

    return {
      Search,
      router,
      ...toRefs(state),
    };
  },
  methods: {
    pageJump(path: string) {
      this.router.push({
        path: path,
      });
    },
    toLogin() {
      this.router.replace({
        path: '/login',
      });
    },
  },
});
</script>

<style lang="scss" scoped>
.header-container {
  width: 100%;
  border-bottom: 1px solid #ddd;
}
.header {
  width: 1120px;
  margin: 0 auto;
  height: 138px;

  .logo {
    width: 100%;
    height: 100px;
    display: flex;
    justify-content: space-between;

    img {
      height: 60px;
      margin-top: 20px;
    }

    .search {
      display: flex;
      height: 42px;
      margin-top: 29px;
      margin-right: 30px;

      div {
        width: 200px;
        line-height: 42px;

        span {
          padding-right: 26px;
          float: right;
          position: relative;
          cursor: pointer;

          &:first-child::after {
            content: '';
            position: absolute;
            right: 70px;
            top: 12px;
            width: 1px;
            height: 18px;
            background-color: #000;
          }
        }
      }
      &::v-deep .el-input__wrapper {
        box-shadow: none;
        border-bottom: 1px solid #ccc;
        border-radius: 0px;
      }
      &::v-deep .el-input__suffix-inner {
        color: red;
        font-size: 18px;
      }
    }
  }
  .nav {
    width: 100%;
    height: 38px;
    font-size: 14px;

    ul {
      width: 605px;
      height: 100%;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;

      li {
        line-height: 38px;
        cursor: pointer;
      }
    }
  }
}
</style>
